package com.elitel.frame.base.controller;

import com.elitel.frame.base.service.CfgMoreJoinService;
import com.elitel.frame.base.service.DBServerService;
import com.elitel.frame.main.entity.CfgMoreJoin;
import com.elitel.frame.main.entity.ext.Census;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * created by guoyanfei on 2019/3/21
 */
@Controller
@RequestMapping("/system/morejoin")
public class MoreJoinController {

    private static final Logger logger =LoggerFactory.getLogger(MoreJoinController.class);

    @Autowired
    private CfgMoreJoinService cfgMoreJoinService;

    @Autowired
    private DBServerService dBServerServiceImpl;

    @RequestMapping("/addMoreJoinService")
    @ResponseBody
    public Integer addMoreJoinService(@Valid String servertype , @Valid String pCode, @RequestBody CfgMoreJoin cfgMoreJoin){
        Integer result = 0;
        try {
            CfgMoreJoin isExist = cfgMoreJoinService.getCfgMoreJoinByGuid(cfgMoreJoin.getGuid());
            result = isExist != null ? 2 : cfgMoreJoinService.insertCfgMoreJoinService(servertype,pCode,cfgMoreJoin);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage(),e);
        }

        return result;
    }


    @RequestMapping("/getMoreJoinService")
    @ResponseBody
    public CfgMoreJoin getMoreJoinService(@Valid String servercode){
        return cfgMoreJoinService.getCfgMoreJoinByGuid(servercode);
    }


    @RequestMapping("/updateMoreJoinService")
    @ResponseBody
    public Integer updateMoreJoinService(@RequestBody CfgMoreJoin cfgMoreJoin){
        return cfgMoreJoinService.updateMoreJoinService(cfgMoreJoin);
    }
}
